package noncomunicating.classes;

import comunicating.classes.ServerLoop;

public class Control extends abstracts.Step{

	public Control(Request request) {
		super(request);
		
		request.setStatusCode(200);
		request.setStatus("OK");
		
		if(request.getModifiers().containsKey("password") && ServerLoop.doPasswordsMatch(request.getModifiers().get("password"))){
			request.setFileContent("<html><body><h1>Settings Changed</h1></body></html>".getBytes());
		}
		else if(request.getModifiers().containsKey("password") && !ServerLoop.doPasswordsMatch(request.getModifiers().get("password"))){
			request.setFileContent("<html><body><h1>Password Incorrect</h1></body></html>".getBytes());
		}
		else{
			request.setFileContent(ServerLoop.getControlPage());
		}
		
		ServerLoop.liveLoadSettings(request.getModifiers());
		
	}

	@Override
	public void printOutput(boolean verbose) {
		System.out.println(getOutput(verbose));
		
	}

	@Override
	public String getOutput(boolean verbose) {
		return request.getName() + ": Settings Re-Loaded\n";
	}

}
